package com.edais.actions;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.edais.service.QuanHouPrizeService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;


@Controller
@RequestMapping("/prize")

public class PrizeAction {
	private static final Log logger = LogFactory.getLog(PrizeAction.class);
	
	@Autowired
	private QuanHouPrizeService quanHouPrizeService;
	
	/**
	 * 查询我的兑奖信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/prizeList")
	public void prizeList(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		try{
			jsonMap = this.quanHouPrizeService.queryQuanHouPrizeListByMobile(paramsMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("查询我的兑奖信息异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 获取加息券
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/addRateRisesCoupons")
	public void addRateRisesCoupons(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		try{
			jsonMap = this.quanHouPrizeService.addRateRisesCoupons(paramsMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("获取加息券异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}

	/**
	 * 获取流量
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/addMobileFlows")
	public void addMobileFlows(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		
		try{
			jsonMap = this.quanHouPrizeService.addMobileFlows(paramsMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			e.printStackTrace();
			logger.error("获取流量异常:" + e.getMessage());
			String result = CommonUtil.setResultStringCn(
				new HashMap<String, Object>(),Consts.ERROR_CODE, "",e.getMessage());
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}
	}

}
